<?php
# Part of RASS unittest fixtures: user authentication.
# Copyright (C) 2008 rambla.be
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

class RatsHttpsTest extends UnitTestCase {
    function TestRatsClientlib() {
        $this->UnitTestCase("Https Tests");
    }

    function testNoAuth() {
      $status = 0;
      try {
        $rats = new Rats(null, null, BASE);
        $rats->setSSL(True);
        $feed = $rats->getInputFeed();
      }
      catch(Zend_Gdata_App_Exception $e) {
        $status = $e->getResponse()->getStatus();
      }
      $this->assertEqual($status, 401);
    }

    function testNoPwd() {
      $status = 0;
      try {
        $rats = new Rats(SEC_USER, null, BASE);
        $rats->setSSL(True);
        $entry = $rats->getInputFeed();
      }
      catch(Zend_Gdata_App_Exception $e) {
        $status = $e->getResponse()->getStatus();
      }
      $this->assertEqual($status, 401);
    }
    
    function testGetOwnUserProfile() {
      $status = 0;
      try {
        $rats = new Rats(SEC_USER, SEC_PWD, BASE);
        $rats->setSSL(True);
        $entry = $rats->getUserEntry();
      }
      catch(Zend_Gdata_App_Exception $e) {
        $status = $e->getResponse()->getStatus();
      }
      $status = $rats->getResponse()->getStatus();
      $this->assertEqual($status, 200);
    }
    

    function testCreateRassInput() {
      try {
        # create input profile (rass, no base uri)
        $rats = new Rats(SEC_USER, SEC_PWD, BASE);
        $rats->setSSL(True);
        $input_entry = $rats->createInput(INPUT_RASS, "Me know nothing", METHOD_RASS, CDN01);
        $this->assertEqual($input_entry->content->params->name->text, INPUT_RASS);
        # retrieve the input profile
        $input2_entry = $rats->getInputEntry($input_entry->id->text);
        $this->assertEqual($input_entry->content->params->name->text, $input2_entry->content->params->name->text);
        # retrieve the input profile using the id as input
        $input3_entry = $rats->getInputEntryFromId($input_entry->content->params->id->text);
        $this->assertEqual($input2_entry->content->params->name->text, $input3_entry->content->params->name->text);
        # delete the input
        $rats->deleteInput($input_entry->id->text);
        $this->assertEqual($rats->getResponse()->getStatus(), 204);
      }
      catch(Zend_Gdata_App_Exception $e) {
        assert(False);
      }
    }
    
    function testGetInputFeed() {
      $entriesFound = 0;
      try {
        $rats = new Rats(SEC_USER, SEC_PWD, BASE);
        $rats->setSSL(True);
        $feed = $rats->getInputFeed();
      }
      catch(Zend_Gdata_App_Exception $e) {
        assert(False);
      }
      $status = $rats->getResponse()->getStatus();
      $this->assertEqual($status, 200);
    }
    
    
}